home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
listvw.exe
/
TI1033.ASC
< prev
Wrap
Text File
|
1993-06-30
|
14KB
|
595 lines
PRODUCT : Borland C++ NUMBER : 1033
VERSION : 3.x
OS : DOS
DATE : June 30, 1993 PAGE : 1/9
TITLE : Example of derived TListViewer for Turbo Vision.
// ============ //
// TESTLIST.CPP //
// ============ //
#define Uses_TRect
#define Uses_TKeys
#define Uses_TEvent
#define Uses_TDialog
#define Uses_TListViewer
#define Uses_TMenu
#define Uses_TMenuItem
#define Uses_TMenuBar
#define Uses_TDeskTop
#define Uses_TApplication
#include <tv.h>
#pragma hdrstop
#include "testlist.h"
class TTestApp : public TApplication
{
public:
TTestApp() : TApplication(),
TProgInit( initStatusLine, initMenuBar,
initDeskTop )
{}
static TMenuBar *initMenuBar( TRect r );
virtual void handleEvent( TEvent& event );
};
TMenuBar *TTestApp::initMenuBar( TRect r )
{
r.b.y = r.a.y + 1;
return new TMenuBar( r, new TMenu(
*new TMenuItem( "~L~ist", cmTTList, kbAltL )
));
}
PRODUCT : Borland C++ NUMBER : 1033
VERSION : 3.x
OS : DOS
DATE : June 30, 1993 PAGE : 2/9
TITLE : Example of derived TListViewer for Turbo Vision.
void TTestApp::handleEvent( TEvent& event )
{
TApplication::handleEvent( event );
if( event.what == evCommand &&
event.message.command == cmTTList )
{
TView *TTLD = (TView *) validView(
new TTestListDialog
);
if( TTLD != 0 )
deskTop->insert( TTLD );
clearEvent( event );
}
}
int main()
{
TTestApp TB;
TB.run();
return 0;
}
// ------------ //
// LISTVIEW.CPP //
// ------------ //
#define Uses_TPoint
#define Uses_TRect
#define Uses_TKeys
#define Uses_TEvent
#define Uses_TDialog
#define Uses_TButton
#define Uses_TScrollBar
#define Uses_TListViewer
#define Uses_MsgBox
PRODUCT : Borland C++ NUMBER : 1033
VERSION : 3.x
OS : DOS
DATE : June 30, 1993 PAGE : 3/9
TITLE : Example of derived TListViewer for Turbo Vision.
#include <tv.h>
#include <string.h>
#pragma hdrstop
#include "testlist.h"
/*
* Data for list viewer: a collection of 80's & 90's rock
* titles with a few earlier ones thrown in for kicks...
*/
char *songTitles[] =
{
"When You Don't See Me",
"Until the End of the World",
"I'm Too Sexy",
"Hungry Like the Wolf",
"I Can't Get Enough",
"You Got Another Thing Coming",
"His Circle and Hers Meet",
"Would I Lie To You?",
"I Melt With You",
"Forever Young",
"Blue Monday",
"Owner of a Lonely Heart",
"Oh L'Amour",
"Shock the Monkey",
"If You Love Somebody Set Them Free",
"Tainted Love",
"Helpless Automaton",
"I Can't Drive 55!",
"Life is a Long Road",
"Talk Talk"
};
const int MAXSTRINGS = (sizeof(songTitles) / sizeof( char * ));
const int MAXLENGTH = 36; // Length of longest song title.
/****************************************************************\
*
* class TTestList
*
*
PRODUCT : Borland C++ NUMBER : 1033
VERSION : 3.x
OS : DOS
DATE : June 30, 1993 PAGE : 4/9
TITLE : Example of derived TListViewer for Turbo Vision.
*
****************************************************************
* TTestList::TTestList
* Initializes range of list viewer, sets maximum length of
* individual strings and sets the grow modes so the viewer will
* grow and shrink with the dialog box window.
\****************************************************************/
TTestList::TTestList( TRect& r,
TScrollBar *aHSB,
TScrollBar *aVSB ) :
TListViewer( r, 1, aHSB, aVSB )
{
maxWidth = MAXLENGTH;
setRange( MAXSTRINGS );
growMode |= gfGrowHiX | gfGrowHiY;
}
/***************************************************************\
* TTestList::setRange
* In addition to setting the range of the listviewer and the
* vertical scrollbar, this also sets the horizontal scrollbar.
*
\***************************************************************/
void TTestList::setRange( short range )
{
TListViewer::setRange( range );
if( hScrollBar != 0 )
hScrollBar->setRange( 0, maxWidth - size.x );
}
/***************************************************************\
* TTestList::getText
* Copies the appropriate string into the buffer passed
* in. If 'item' is out of range, it copies a NULL
* string.
\***************************************************************/
PRODUCT : Borland C++ NUMBER : 1033
VERSION : 3.x
OS : DOS
DATE : June 30, 1993 PAGE : 5/9
TITLE : Example of derived TListViewer for Turbo Vision.
void TTestList::getText( char *dest, short item, short maxLen )
{
if( item >= 0 && item < MAXSTRINGS )
strncpy(dest, songTitles[item], maxLen);
else
dest[0] = '\0';
}
/***************************************************************\
* TTestList::changeBounds
* If the user resizes the list viewer and there is only
* one column, the horizontal scrollbar may need to be
* activated if the viewer is too small (or deactivated if the
* viewer is now large enough for a complete display.) So we
* check for that. Ditto for the vertical scrollbar.
\***************************************************************/
void TTestList::changeBounds( const TRect& bounds )
{
TListViewer::changeBounds( bounds );
if( numCols == 1 && hScrollBar != 0 )
hScrollBar->setParams(
hScrollBar->value, // current
// position in
// bar
0, // minimum
// length
// (usually 0)
maxWidth - size.x, // max length
// minus width
// of viewer
size.x - 1, // page keys
// step a full
// viewer width
1 // arrow keys
// step one
// character
);
}
PRODUCT : Borland C++ NUMBER : 1033
VERSION : 3.x
OS : DOS
DATE : June 30, 1993 PAGE : 6/9
TITLE : Example of derived TListViewer for Turbo Vision.
/****************************************************************\
* TTestList::handleEvent
* We need to handle double click messages, ensuring that
* the mouse is on top of a valid list item and that it
* was the left butt